package com.dp.mallchat.transaction.service;

import com.dp.mallchat.transaction.annotation.SecureInvoke;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

/**
 * @Author: dupeng
 * @CreateTime: 2024-06-30  22:40
 * @Description: MQ工具类
 */
public class MQProducter {


    @Autowired
    private RocketMQTemplate rocketMQTemplate;



    public void sendMessage(String topic, Object message){
        Message<Object> messageBuilder = MessageBuilder.withPayload(message).build();
        rocketMQTemplate.send(topic, messageBuilder);
    }

    @SecureInvoke
    public void sendMessage(String topic, Object message, Object key){
        Message<Object> messageBuilder = MessageBuilder
                .withPayload(message)
                .setHeader("KEYS", key)
                .build();
        rocketMQTemplate.send(topic, messageBuilder);
    }



}
